<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/view/common/kendocommon.jsp"%>

<!DOCTYPE html>
<html>
<head>
<title>评论回复</title>
<meta charset="utf-8">
<style>
table {
	font-size: 12px
}
</style>
<script>
	$(document)
			.ready(
					function() {
						

						
						$("#toolbar")
								.kendoToolBar(
										{
											resizable : false,
											items : [
													{
														type : "separator"
													},
													{
														template : "<label>商品名字</label><input name='product_name' id='product_name' class='k-textbox'>"
													},
													{
														template : "<label>商品代码</label><input name='product_code' id='product_code' class='k-textbox'>"
													},
													{
														template : "<label>业务类型</label><input name='business' id='business'>"
													},
													{
														type : "separator"
													}, {
														type : "button",
														text : "查询",
														click : queryInfo
													} ]
										});
						
						
					    $("#product_name").blur(function(){
					    	queryInfo();
					  });
					    $("#product_code").blur(function(){
					    	queryInfo();
					  });
						
						var name="${param.name}";
						if(name!=null&&name!=''){
							$('#product_name').val(name);
						}
						
						//toUserID=WV00000033&
						dataSource = new kendo.data.DataSource(
								{
									transport : {
										read : {
											//url: spera.spera_consume
											url : spera.spera_consume
													+ "/consumeBackground/getProductList2",
											dataType : "jsonp",
											data : function() {
												return {
													kids_park_id : '04428ed2-a555-11e5-8ece-1051721d3a6c',
													name : $('#product_name').val(),
													code : $('#product_code').val(),
													deptID : '${param.deptID}',
													businessTypeCode:$('#business').val(),
												};
											}
										},
									},

									//group: [{field: "deptName"}],
									serverPaging : true,
									serverFiltering : true,
									pageSize : 10,
									schema : {
										data : "data",
										total : "total",
										model : {
											fields : {

												name : {
													editable : false
												},
												unitPrice : {
													type : "number",
													editable : true
												},
												business_type : {
													editable : false
												},
												code : {
													editable : false
												},
												isDiscount2 : {
													editable : false
												},
												quantity : {
													type : "number",
													editable : true,
													validation : {
														required : true,
														min : 1
													},
													defaultValue : 1
												},
												promotion2:{defaultValue:{promotionTest:"",discountPrice:""}},
												remainQuantity:{
													editable : false
												},
											}
										}
									}
								});							
						
						$("#grid").kendoGrid({
							dataSource : dataSource,
							pageable : {
								refresh : true,
								pageSizes : true,
								buttonCount : 5,
								page : 1,
								pageSize : 10,
								pageSizes : [ 10, 20, 30 ],
								messages : {
									display : "显示 {0}-{1} 共 {2} 项",
									empty : "没有数据",
									itemsPerPage : "每面显示数量",
									first : "第一页",
									last : "最后一页",
									next : "下一页",
									previous : "上一页"
								}
							},
							selectable : "multiple row",
							allowCopy : true,
							groupable : {
								messages : {
									empty : "将列拖拽到此处进行分类查看"
								}
							},
							editable :"incell", /* {
								mode : "incell"
							}, */
							columns : [
	//						{ field:"id", template: "<input type='checkbox' id='#:id#' />",width: "120px",headerTemplate: '<input type="checkbox" id="check-all" />'},
							{
								field : "name",
								title : "商品名",
								width : "200px",
								editable : false
							}, {
								field : "unitPrice",
								title : "单价",
								width : "80px",
								editable : true
							}, {
								field : "business_type",
								title : "业务类型",
								width : "100px",
								editable : false
							}, {
								field : "code",
								title : "商品代码",
								width : "120px",
								editable : false
							}, {
								field : "isDiscount2",
								title : "是否打折",
								width : "80px",
								editable : false
							},
							{
								field : "promotion2.promotionTest",
								title : "促销",
								width : "200px",
								editable : true,
 								template : function(data) {
 									
/*  									if(data.promotion2.promotionTest==null){
 		                        		data.promotion2.promotionTest='';
 		                        	}  */
 								//	console.log(data);
 									
								if (data.promotion2) {								
										return data.promotion2.promotionTest;
									}							
 								},
							editor : function(container, options) {								
									var grid = $("#grid").data("kendoGrid");							
									var rowData = grid.dataItem($(container).parent());						 
																		
									var promotionDate=rowData.promotion;
										//discountPrice
									var input = $("<input/>");
									input.attr("name", options.field);
									input.appendTo(container);
									input.kendoComboBox({
										dataValueField : "discountPrice",
										dataTextField : "promotionTest",
										dataSource : promotionDate,
										select : function(e) {
											var dataItem = e.sender.dataItem(e.item);	
											var curGrid = $("#grid").getKendoGrid();
											var selGridItem = curGrid.select();
											
											if(selGridItem)
											{
												var curDataItem = curGrid.dataItem(selGridItem);
											}
										}
									});
								}
							}, 
														
							{
								field : "quantity",
								title : "数量",
								width : "60px",
								editable : true
							},
							{
								field : "remainQuantity",
								title : "可售数量",
								width : "60px",
								editable : false
							},
							//  { command: ["edit"], title: "操作", width: "100px" }  ,
							{
								command : [ {
									name : "comment",
									text : "添加",
									click : addItems
								} ],
								attributes : {
									style : "text-align:center"
								},
								headerAttributes : {
									style : "text-align:center"
								},
								title : "操作",
								width : "100px"
							} ],

							save : function(e) {
						//		debugger;
							}
						});
						//<span class='k-icon k-i-group'>  ,buttonType:"ImageAndText"
						//$('#grid').css("height",document.body.clientHeight-40);

						/*           $(".fancybox").fancybox({
									openEffect	: 'none',
									closeEffect	: 'none'
								});
						 */

						//  $("#numerictextbox").kendoNumericTextBox();
					

						var business = new kendo.data.DataSource({
							transport : {
								read : {
									url : spera.sperachildrenpark_path
											+ "/common/getBusinessTypeCode2",
									dataType : "jsonp",
									data : function() {
										return {
											type : '1'
										}
									}
								}
								
							}
							

						});
						$("#business").kendoComboBox({
							dataSource : business,
							dataTextField : "name",
							dataValueField : "code"
						});

					});

	var addItems = function(e) {
		var grid = $("#grid").data("kendoGrid");
		var data = grid.dataItem($(e.currentTarget).closest("tr"));

		if (data.quantity == null) {
			alert('请输入数量');
			return false;
		}

		parent.tcaddItem(data);
	}

	var queryInfo = function(e) {
		$("#grid").data("kendoGrid").dataSource.fetch();		
		$("#grid").data("kendoGrid").dataSource.page(1);
	}
	
	
	document.onkeydown=function(event){ 
		var e = event || window.event || arguments.callee.caller.arguments[0]; 
		if(e.keyCode==13){
			queryInfo();
		}
	}

	
</script>

</head>
<body>
	<div id="toolbar" style="margin:2px"></div>
	<div id="grid" style="margin:2px;font-size:10px"></div>


</body>
</html>
